import requests

from yige_utils.work_utils import work_logger


class ChromeClient:
    session = requests.Session()
    session.headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
    }

    @work_logger()
    def send_request(self, *args, **kwargs) -> requests.Response:
        """
        发送请求
        :return: 请求的响应对象
        """
        res = self.session.get(*args, **kwargs)
        # raise TimeoutError('模拟异常')
        if res.status_code // 100 != 2:
            raise Exception(f'响应状态码异常{res.status_code}:{res.text}')
        return res

    @work_logger()
    def send_request_post(self, *args, **kwargs) -> requests.Response:
        """
        发送请求
        :return: 请求的响应对象
        """
        res = self.session.post(*args, **kwargs)
        # raise TimeoutError('模拟异常')
        if res.status_code // 100 != 2:
            raise Exception(f'响应状态码异常{res.status_code}:{res.text}')
        return res
